// <copyright file="RemoteDataSource.cs" company="YUIAsp.Net">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>raul popescu</author>
// <email>dev@yuiasp.net</email>
// <date>2009-01-30</date>
// <summary>YUIAsp.Net File</summary>

using System;
using System.Globalization;
using System.Text;

namespace YUIAspNet
{
    /// <summary>
    /// Represents a remote data source
    /// </summary>
    public class RemoteDataSource : DataSourceBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="RemoteDataSource"/> class.
        /// </summary>
        public RemoteDataSource() : base(DataSourceType.Remote) {}

        /// <summary>
        /// Gets or sets the data URL.
        /// </summary>
        /// <value>The data URL.</value>
        public new Uri DataUrl 
        {
            get { return base.DataUrl; }
            set { base.DataUrl = value; }
        }

        /// <summary>
        /// Adds the column.
        /// </summary>
        /// <param name="name">The name.</param>
        public void AddColumn(string name)
        {
            Keys.Add(name);
        }

        /// <summary>
        /// Adds the setting.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public void AddSetting(string key, object value)
        {
            AdditionalItems.Add(key, value);
        }

        /// <summary>
        /// Serializes the specific properties foreach implementor.
        /// </summary>
        /// <returns></returns>
        protected override StringBuilder SerializeSpecificData()
        {
            if (DataUrl == null)
                throw new InvalidOperationException("You need to set the DataUrl property for the RemoteDataSource!");
            return new StringBuilder().AppendFormat(CultureInfo.InvariantCulture, "\"URL\": \"{0}\"", DataUrl);
        }
    }
}
